<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Category_Model extends CI_Model
{

	function get_featured_product(){

		//$this->db->where('product_id', $product_id);
		$this->db->limit(12);
		$this->db->where('status',1);
		$this->db->order_by('product_id DESC');

		$query = $this->db->get('product');
		if ($query->num_rows() > 0 ) return $query->result();
		return array();		

	}
	
	function select($product_seo_name){
        $query = $this->db->get_where('product', array('product_seo_name'=>$product_seo_name));
		if($query ->num_rows() >0 ) {
			foreach($query ->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
    }

	function get_list_product($category_id=''/*, $page='', $limit=''*/){

		$this->db->where('category_id', $category_id);
		$this->db->order_by('date_add DESC');
		
		/*if(!empty($limit))
		$this->db->limit($limit,$page);*/
		
		$query = $this->db->get('product');

		//echo $this->db->last_query();

		if ($query->num_rows() > 0) return $query->result();
		return array();
	}
	
	function get_category(){
		$this->db->where('parent', 0);

		$query = $this->db->get('product_category');
		if ($query->num_rows() > 0) return $query->result();
		return NULL;
	}

	function get_category_child($parent){
		$this->db->where('parent', $parent);

		$query = $this->db->get('product_category');
		if ($query->num_rows() > 0) return $query->result();
		return array();
	}
	
}